﻿using MainFrameDesign.ContentContorl;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace MainFrameDesign.Action
{
    public class DragObj
    {
        public Div CurrentDiv = null;
        public Div ActionDiv = null;
        public Dom Root = null;
        public Point CurrentPoint=new Point(0,0);
        private Point OldPoint = new Point(-1, -1);
        private AppendEnum OldEnum = AppendEnum.None;
        private DesignControl MyPan = null;
        public string TypeName { get; set; }
        

        public DragObj(DesignControl mypan,Dom dom)
        {
            this.MyPan = mypan;
            this.Root = dom;
        }


        public void Leave() 
        {
            ActionDiv = null;
            OldEnum = AppendEnum.None;
        }


        public void Hover()
        {
            if(CurrentPoint==OldPoint)
            {
                return;
            }
            OldPoint = CurrentPoint;
            if (CurrentDiv.Parent!=null&&CurrentDiv.Rect.Contains(CurrentPoint)) 
            {
                return;
            }
            AppendEnum CurrentEnum = AppendEnum.None;
            Div SelDiv = this.Root.IsHover(CurrentPoint, ref CurrentEnum);
            if (SelDiv == null || CurrentEnum == AppendEnum.None) 
            {
                return;
            }
            if (SelDiv == ActionDiv && CurrentEnum == OldEnum) 
            {
                return;
            }
            OldEnum = CurrentEnum;
            ActionDiv = SelDiv;
            CurrentDiv.RemoveSelf(false);
            if (CurrentEnum == AppendEnum.Before) 
            {
                ActionDiv.Before(CurrentDiv, false);
            }
            else if (CurrentEnum == AppendEnum.Content)
            {
                ActionDiv.AppendChild(CurrentDiv, false);
            }
            else 
            {
                ActionDiv.After(CurrentDiv, false);
            }
            this.Root.CallDrawPar();
            this.MyPan.InvalidateDesign();
        }


    }
}
